﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using CottagesOfHope.Core.Concrete;
using CottagesOfHope.Core.Abstract;
using CottagesOfHope.Core.Models;
using WebMatrix.WebData;
using CottagesOfHope.Filters;

namespace CottagesOfHope.Controllers
{
    public class TaskController : Controller
    {
        private readonly ICottagesOfHopeRepository _cottagesOfHopeRepository;

        public TaskController(ICottagesOfHopeRepository cottagesOfHopeRepository)
        {
            _cottagesOfHopeRepository = cottagesOfHopeRepository;
        }
        //
        // GET: /Event/
      /*  [HttpGet]
        public ActionResult Edit()
        {
            TaskEditModel model = new TaskEditModel
            {
                Task = new Tasks {StartDate = new DateTime(2010, 12, 15),
                    EndDate = new DateTime(2013, 03, 25)}
            };
            return View(model);
        }
        [HttpPost]
        public ActionResult Edit(Tasks task)
        {
            string message = null;
            if (ModelState.IsValid)
            {
                // would do validation & save here...
                message = "Saved " + DateTime.Now;
            }
            TaskEditModel model = new TaskEditModel
            {
                Task = task,
                Message = message
            };
            return View(model);
        }

       public ActionResult Index()
        {
            ViewBag.Message = "This is a test of the tasks page";
            return View();
        }*/

       [HttpGet]
       public ActionResult Create()
       {
           return View();
       }

       [Authorize(Roles = "Client")]
       [HttpPost]
       [ValidateAntiForgeryToken]
       public ActionResult Create(Tasks task)
       {
           if (ModelState.IsValid)
           {
               task.UserId = WebSecurity.CurrentUserId;
               _cottagesOfHopeRepository.SaveTask(task);
               return RedirectToAction("Index");
           }

           return View(task);
       }

       [Authorize(Roles = "Client")]
       public ActionResult Index(Tasks task)
       {
           return View(_cottagesOfHopeRepository.Tasks);
       }

       [HttpPost]
       public ActionResult Delete(Tasks task)
       {

           return View(_cottagesOfHopeRepository.Tasks);
       }
    }
}

//Send View model instead of a viewBag

